Adding a Button to a ControlBar

Description

You can add a button to a ControlBar and then associate an action (i.e. some Javascript code) to run when the button is tapped.

To see how to add a button to a ControlBar watch the video or read the guide below.

Adding a Button to a ControlBar

In this video we show how you can add a button to a ControlBar and then associate an action (i.e. some Javascript code) to run when the button is tapped.

Download Component

2016-09-14

This guide demonstrates how to create a button that can navigate through a list control using a javascript action.

Add a Button with an SVG Icon to a ControlBar

  1. In the UX Builder open the Properties page. Click on the [...] button next to the Style name property in the UX Properties section.

    images/addb.png
  2. In the 'Select Style' dialog under 'Location' select 'System', then choose the 'Alpha' style from the top of the list. Click OK

    images/addb2.png
    Choosing the Alpha style will give you access to a large selection of pre-defined mobile SVG icons.
  3. Open the 'Controls' page. From the toolbar menu on the Controls page check the 'Mobile' checkbox.

    images/addb3.png
  4. Open the 'Panels' menu and click the [Panel Navigator] option to add a Panel Navigator to the control.

    images/addb4.png
  5. Highlight the Panel Navigator in the tree. Open the 'Containers menu' on the left and click on the [Container] option.

    images/addb5.png
  6. Select 'PanelHeader' from the Container Type list on the Insert Container dialog. Click 'Insert After.

    images/addb6.png
  7. Highlight the PanelHeader. Open the 'Other Controls' menu. Scroll down the list and select [ControlBar] to add a control bar to the Panel Header.

    images/addb7.png
  8. Highlight the ControlBar control. In the control properties list on the right click the [...] button next to the ControlBar properties property to open the ControlBar Builder.

    images/addb8.png
  9. In the ControlBar Builder open the 'Items' pane and click the 'Add ControlBar Item' button.

    images/addb9.png
  10. Select the 'button' option in the 'Item Type' list and click OK.

    images/addb10.png
  11. Still on the 'Items' pane, scroll down the button's properties list to the 'Button Settings' section. Click the dropdown next to the 'Button layout' property and select 'Image only'.

    images/addb11.png
  12. Click the [...] button next to the Icon property.

    images/addb12.png
  13. In the Specify Image dialog check the 'SVG Icon' radio button and then click the 'Select' button.

    images/addb13.png
  14. From the style SVG icons select the down arrow icon. Click OK and OK again.

    images/addb14.png
    The 'Size' slider at the top of the SVG Icon dialog lets you set the size of the icon class.
  15. Open the ControlBar Layout pane and click the 'Add Layout' button.

    images/addb15.png
  16. Give the layout a name, like 'Layout1', and click OK.

    images/addb16.png
  17. Highlight the named layout. Click the 'Add Line' button in the Layout Definition section of the pane.

    images/addb17.png
  18. Click the 'Add' button in the 'After' section of the Edit Layout Line dialog.

    images/addb18.png
    'before', 'middle', and 'after' are used instead of left or right because layouts can also be vertical.
  19. Select 'Button1' and click OK. Click OK again to close the ControlBar Builder.

    images/addb19.png
  20. Run the component in Working Preview. You should see the icon button appear in a control bar. When you hover over the icon it should appear blue. The button doesn't have any functionality yet, this will be added in the next section.

    images/addb20.png

ControlBar Buttons and Javascript

This is a continuation of the section above.

  1. On the UX Controls page highlight [PanelHeader End:PANELHEADER_1]. Open the 'Panels' menu and select the [Panel Card] option. Click on 'Insert After' to add a Panel Card underneath the Panel Header.

    images/bjs.png
  2. Highlight the Panel Card. Open the 'Data Controls' menu and click on [List] in order to add a list control inside the Panel Card.

    images/bjs2.png
  3. Highlight the List control. In the properties menu on the right click on the [...] box next to the 'List properties' property in the 'List Properties' section. The List Builder will open.

    images/bjs3.png
  4. Open the Data Source pane of the List Builder. Set the Data Source Type to be 'SQL'.

    images/bjs4.png
  5. In the SQL Data Source properties section set the Connection string to be the Northwind database.

    images/bjs5.png
  6. Set the 'Table name' property to be the 'Customers' table.

    images/bjs6.png
  7. Click on the [...] button next to the 'Field list' property, select the 'ContactName' and 'City' fields and click OK.

    images/bjs7.png
  8. Use the blue > arrow button to move the 'ContactName' and 'City' fields from the 'Available Fields' list to the 'Columns in List' area. Click OK to close the List Builder.

    images/bjs8.png
  9. Highlight the ControlBar control. In the properties section on the right click on the 'ControlBar properties' property to open the ControlBar Builder.

    images/bjs9.png
  10. Open the 'Actions' pane and click the 'Add Action' button.

    images/bjs10.png
  11. Give the action the name 'next'.

    images/bjs11.png
  12. Add the following javascript code to define the new action.

    var lObj = {dialog.object}.getControl('list1');
    lObj.navigate('next');
    images/bjs12.png
  13. Open the 'Items' pane and highlight 'Button1'. In the 'Item Actions' section click the [...] button next to the Click property.

    images/bjs13.png
  14. Select the 'next' action that you just defined.

    images/bjs14.png
  15. Click OK to close the List Builder. Run the component in Working Preview. Now when you click on the 'down' icon you should see the cursor move through the list.

    images/bjs15.png

Adding Additional Navigation Actions

You can add additional navigation to the example shown in the section above. The following javascript should work if you wanted to add an action to a button in the ControlBar that moves a cursor to the previous field in a list control.

var lObj = {dialog.object}.getControl('list1');
lObj.navigate('previous');

To create an item that skips to the first row of the list control, define an action with this javascript:

var lObj = {dialog.object}.getControl('list1');
lObj.navigate('home');

To cause the cursor in the list control to move to the end of the list define an action with this javascript:

var lObj = {dialog.object}.getControl('list1');
lObj.navigate('end');